<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-29 23:43:29
 * @lastTime 2020-04-30 00:25:02
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Design\Other\Repository;

class PostId
{

    private $id;


    public static function fromInt(int $id) : PostId
    {
        self::ensureIsValid($id);
        return new self($id);

    }//end fromInt()


    private function __construct(int $id)
    {
        $this->id = $id;

    }//end __construct()


    public function toInt() : int
    {
        return $this->id;

    }//end toInt()


    public static function ensureIsValid(int $id)
    {
        if ($id <= 0) {
            throw new \InvalidArgumentException('Invalid id given');
        }

    }//end ensureIsValid()


}//end class
